import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split


def dataAnalyse():
    print("恶性肿瘤分析")
    # 1-数据集切分-留出法
    # 0-常量定义
    folder_path = "./resources/"
    train_file_path = folder_path + "breast-cancer-train.csv"

    # 1-读取CSV文件
    # 调用 pandas 工具包的 read_csv 函数，传入地址参数，返回数据并且存至变量 df_train
    column_names = ['Clump Thickness', 'Cell Size', 'Type']
    df_train = pd.read_csv(train_file_path, names=column_names)

    # 2-空数据处理
    # 将'?'替换为标准缺失值(小心使用inplace=True，会改变原始数据类型)
    df_train = df_train.replace(to_replace='?', value=np.nan)
    # 丢弃含有标准缺失值的行(但是当前方法在其他方法中可以正常使用)
    df_train = df_train.dropna(how='any')
    print(df_train)

    # 3-数据集切分
    X = df_train[column_names[1:2]]
    y = df_train[column_names[2]]
    # 使用留出法将数据集划分为训练集和测试集
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
    # 输出训练集和测试集的大小
    print("训练集数据X:", X)
    print("训练集数据y:", y)
    print("训练集大小:", len(X_train))
    print("测试集大小:", len(X_test))


if __name__ == '__main__':
    dataAnalyse()
